<template>
  <div class="dashboard-container">
    <!-- 顶部导航栏 -->
    <header class="top-header">
      <div class="header-left">
        <h1>数据可视化平台</h1>
      </div>
      <nav class="header-middle">
        <router-link to="/matplotlib" class="nav-item">matplotlib可视化</router-link>
        <router-link to="/seaborn" class="nav-item">seaborn可视化</router-link>
        <router-link to="/pyecharts" class="nav-item">pyecharts可视化</router-link>
      </nav>
      <div class="header-right">
        <span class="time-display">{{ currentTime }}</span>
        <div class="user-info">
          <div class="user-avatar">
            <img src="../assets/tx.jpg" alt="用户头像">
          </div>
          <span class="user-name">{{ userInfo.name }}</span>
        </div>
      </div>
    </header>
    <!-- 可视化图容器 -->
    <div class="visualization-area">
      <div class="left-section">
        <div class="visualization-box">
          <h3 class="chart-title">堆叠柱状图 - 多维度数据对比</h3>
          <img src="../assets/堆叠柱状图.png" alt="Matplotlib 图表" class="matplotlib-image" @click="openImageModal('../assets/堆叠柱状图.png', '堆叠柱状图 - 多维度数据对比')">
        </div>
        <div class="visualization-box">
          <h3 class="chart-title">双Y轴折线图 - 多指标关联分析</h3>
          <img src="../assets/双Y轴折线图.png" alt="Matplotlib 图表" class="matplotlib-image" @click="openImageModal('../assets/双Y轴折线图.png', '双Y轴折线图 - 多指标关联分析')">
        </div>
      </div>
      <div class="middle-section">
        <div class="visualization-box large-box">
          <h3 class="chart-title">雷达图 - 多维指标评估</h3>
          <img src="../assets/雷达图.png" alt="Matplotlib 图表" class="matplotlib-image" @click="openImageModal('../assets/雷达图.png', '雷达图 - 多维指标评估')">
        </div>
      </div>
      <div class="right-section">
        <div class="visualization-box">
          <h3 class="chart-title">面积图 - 趋势累积分析</h3>
          <img src="../assets/面积图.png" alt="Matplotlib 图表" class="matplotlib-image" @click="openImageModal('../assets/面积图.png', '面积图 - 趋势累积分析')">
        </div>
        <div class="visualization-box">
          <h3 class="chart-title">饼图 - 占比分析</h3>
          <img src="../assets/饼图+环形图.png" alt="Matplotlib 图表" class="matplotlib-image" @click="openImageModal('../assets/饼图+环形图.png', '饼图 - 占比分析')">
        </div>
      </div>
    </div>
    
    <!-- 图片模态框 -->
    <div class="image-modal" v-if="showModal" @click="closeImageModal">
      <div class="modal-content" @click.stop>
        <span class="close-button" @click="closeImageModal">&times;</span>
        <h3 class="modal-title">{{ modalTitle }}</h3>
        <img :src="modalImage" alt="放大图片" class="modal-image">
        <div class="image-description">
          <p>点击图片外部区域关闭</p>
        </div>
      </div>
    </div>
  </div>
</template>

<!-- 修改打开图片模态框的方法 -->
<script lang="ts" setup>
import { ref, onMounted, reactive } from 'vue';

// 当前时间
const currentTime = ref(new Date().toLocaleString());

// 用户信息，默认已登录状态
const userInfo = reactive({
  name: 'Admin',
  role: '管理员',
  department: '数据分析部',
  avatar: 'https://secure.gravatar.com/avatar/00000000000000000000000000000000?d=mp&f=y'
});

// 模态框状态
const showModal = ref(false);
const modalImage = ref('');
const modalTitle = ref('');

// 打开图片模态框
const openImageModal = (imageSrc: string, title: string) => {
  modalImage.value = new URL(imageSrc, import.meta.url).href;
  modalTitle.value = title;
  showModal.value = true;
  document.body.style.overflow = 'hidden'; // 防止背景滚动
  
  // 添加调试信息
  console.log('打开模态框', modalImage.value, title);
};

// 关闭图片模态框
const closeImageModal = () => {
  showModal.value = false;
  document.body.style.overflow = ''; // 恢复背景滚动
};

// 实时更新时间
onMounted(() => {
  const timer = setInterval(() => {
    currentTime.value = new Date().toLocaleString();
  }, 1000);

  // 添加ESC键关闭模态框
  window.addEventListener('keydown', (e) => {
    if (e.key === 'Escape' && showModal.value) {
      closeImageModal();
    }
  });

  return () => {
    clearInterval(timer);
    window.removeEventListener('keydown', (e) => {
      if (e.key === 'Escape' && showModal.value) {
        closeImageModal();
      }
    });
  };
});
</script>

<style scoped>
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;700&display=swap');

/* 全局重置样式 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.dashboard-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  position: fixed;
  top: 0;
  left: 0;
  background-color: #0a0e17;
  background-image: 
    radial-gradient(circle at 50% 50%, rgba(37, 93, 217, 0.1) 0%, transparent 80%),
    linear-gradient(to bottom, rgba(0, 30, 60, 0.4) 0%, transparent 100%),
    repeating-linear-gradient(to right, transparent, transparent 50px, rgba(6, 78, 144, 0.05) 50px, rgba(6, 78, 144, 0.05) 51px),
    repeating-linear-gradient(to bottom, transparent, transparent 50px, rgba(6, 78, 144, 0.05) 50px, rgba(6, 78, 144, 0.05) 51px);
  color: #e0f7ff;
  font-family: 'Orbitron', sans-serif;
  overflow: hidden;
}

.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background-color: rgba(16, 24, 39, 0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(0, 195, 255, 0.3);
  box-shadow: 0 0 20px rgba(0, 195, 255, 0.2);
  color: #e0f7ff;
  width: 100%;
  flex-shrink: 0;
  z-index: 10;
}

.header-left h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  background: linear-gradient(90deg, #00c3ff, #60efff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 10px rgba(0, 195, 255, 0.5);
}

.header-middle {
  display: flex;
  gap: 30px;
}

.nav-item {
  color: #e0f7ff;
  text-decoration: none;
  transition: all 0.3s ease;
  position: relative;
  padding: 5px 10px;
  font-size: 0.9rem;
  letter-spacing: 1px;
}

.nav-item:hover {
  color: #60efff;
  text-shadow: 0 0 10px rgba(0, 195, 255, 0.8);
}

.nav-item::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, #00c3ff, transparent);
  transition: width 0.3s ease;
}

.nav-item:hover::after {
  width: 100%;
}

.header-right {
  display: flex;
  gap: 20px;
  font-size: 0.9rem;
  align-items: center;
}

.time-display {
  background-color: rgba(0, 30, 60, 0.5);
  padding: 5px 10px;
  border-radius: 4px;
  border: 1px solid rgba(0, 195, 255, 0.3);
  box-shadow: 0 0 5px rgba(0, 195, 255, 0.2);
}

/* 新增用户信息样式 */
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: rgba(0, 30, 60, 0.5);
  padding: 5px 10px;
  border-radius: 4px;
  border: 1px solid rgba(0, 195, 255, 0.3);
  box-shadow: 0 0 5px rgba(0, 195, 255, 0.2);
  transition: all 0.3s ease;
}

.user-info:hover {
  box-shadow: 0 0 10px rgba(0, 195, 255, 0.4);
  border-color: rgba(0, 195, 255, 0.5);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(0, 195, 255, 0.5);
  box-shadow: 0 0 8px rgba(0, 195, 255, 0.4);
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-name {
  font-weight: 500;
  letter-spacing: 1px;
  color: #60efff;
  text-shadow: 0 0 5px rgba(0, 195, 255, 0.5);
}

/* 其余样式保持不变 */
.visualization-area {
  display: flex;
  flex: 1;
  width: 100%;
  padding: 20px;
  gap: 20px;
  position: relative;
  overflow: auto; /* 添加滚动条以防内容溢出 */
}

.visualization-area::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 30%, rgba(37, 93, 217, 0.15) 0%, transparent 70%),
    radial-gradient(circle at 80% 70%, rgba(37, 93, 217, 0.15) 0%, transparent 70%);
  pointer-events: none;
  z-index: -1;
}

.left-section,
.middle-section,
.right-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.left-section {
  flex: 1;
}

/* 修改中间区域样式，确保雷达图居中 */
.middle-section {
  flex: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center; /* 添加这一行使内容水平居中 */
}

.middle-section .large-box {
  flex: 1;
  height: 620px;
  width: 100%; /* 确保宽度占满 */
  display: flex; /* 添加这一行 */
  flex-direction: column; /* 添加这一行 */
  align-items: center; /* 添加这一行使内容水平居中 */
  justify-content: center; /* 添加这一行使内容垂直居中 */
}

/* 确保雷达图图片居中显示 */
.large-box .matplotlib-image {
  max-height: 85%;
  max-width: 90%; /* 可以适当调整这个值 */
  display: block;
  margin: 0 auto; /* 水平居中 */
}

.right-section {
  flex: 1;
}

.middle-section .large-box {
  flex: 1;
  height: 620px; /* 调整高度以填充整个中间区域 */
}

/* 调整动画延迟，移除了不存在的元素的动画 */
.left-section .visualization-box:nth-child(1) { animation-delay: 0s; }
.left-section .visualization-box:nth-child(2) { animation-delay: 1s; }
.middle-section .visualization-box { animation-delay: 1.5s; }
.right-section .visualization-box:nth-child(1) { animation-delay: 0.5s; }
.right-section .visualization-box:nth-child(2) { animation-delay: 1.5s; }
.right-section .visualization-box:nth-child(3) { animation-delay: 2.5s; }

/* 添加图表标题样式 */
.chart-title {
  font-size: 1rem;
  font-weight: 500;
  margin-bottom: 15px;
  color: #60efff;
  text-shadow: 0 0 8px rgba(0, 195, 255, 0.6);
  letter-spacing: 1px;
  border-bottom: 1px solid rgba(0, 195, 255, 0.3);
  padding-bottom: 8px;
  position: relative;
}

.chart-title::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 50px;
  height: 2px;
  background: linear-gradient(90deg, #00c3ff, transparent);
}

/* 添加图片样式 */
.matplotlib-image {
  width: auto; /* 改为自动宽度 */
  height: auto;
  max-width: 100%;
  max-height: 85%; /* 限制最大高度为容器的85% */
  object-fit: contain;
  margin-top: auto;
  margin-bottom: auto;
  border-radius: 4px;
  transition: all 0.3s ease;
  align-self: center; /* 居中显示 */
}

.large-box .matplotlib-image {
  max-height: 85%; /* 大图表框中的图片高度 */
}

/* 添加图片悬停效果 */
.matplotlib-image {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 85%;
  object-fit: contain;
  margin-top: auto;
  margin-bottom: auto;
  border-radius: 4px;
  transition: all 0.3s ease;
  align-self: center;
  cursor: pointer; /* 鼠标指针变为手型 */
  box-shadow: 0 0 10px rgba(0, 195, 255, 0.2);
}

.matplotlib-image:hover {
  transform: scale(1.05);
  box-shadow: 0 0 15px rgba(0, 195, 255, 0.4);
}

/* 模态框样式 */
.image-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
  animation: fadeIn 0.3s ease;
}

.modal-content {
  position: relative;
  background-color: rgba(16, 24, 39, 0.9);
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 0 30px rgba(0, 195, 255, 0.4);
  max-width: 90%;
  max-height: 90%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid rgba(0, 195, 255, 0.3);
  animation: scaleIn 0.3s ease;
}

.close-button {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 24px;
  color: #60efff;
  cursor: pointer;
  transition: all 0.3s ease;
}

.close-button:hover {
  color: #ff4757;
  transform: scale(1.2);
}

.modal-title {
  color: #60efff;
  margin-bottom: 15px;
  text-align: center;
  width: 100%;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(0, 195, 255, 0.3);
}

.modal-image {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 0 20px rgba(0, 195, 255, 0.3);
  display: block; /* 确保图片正确显示 */
}

.image-description {
  margin-top: 15px;
  color: #e0f7ff;
  text-align: center;
  font-size: 0.9rem;
  opacity: 0.7;
}

/* 动画效果 */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
</style>

<!-- 修复样式冲突，只保留一个 .matplotlib-image 定义 -->
<style scoped>
.matplotlib-image {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 85%;
  object-fit: contain;
  margin-top: auto;
  margin-bottom: auto;
  border-radius: 4px;
  transition: all 0.3s ease;
  align-self: center;
  cursor: pointer; /* 鼠标指针变为手型 */
  box-shadow: 0 0 10px rgba(0, 195, 255, 0.2);
}

.matplotlib-image:hover {
  transform: scale(1.05);
  box-shadow: 0 0 15px rgba(0, 195, 255, 0.4);
}

/* 修改模态框图片样式，确保图片能够正确显示 */
.modal-image {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 0 20px rgba(0, 195, 255, 0.3);
  display: block; /* 确保图片正确显示 */
}

.image-description {
  margin-top: 15px;
  color: #e0f7ff;
  text-align: center;
  font-size: 0.9rem;
  opacity: 0.7;
}

/* 动画效果 */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
</style>